$(function () {
    //变量抽取
    var sales_dataGrid = $("#sales_dataGrid");

    /* 缴费处理 数据表格 */
    sales_dataGrid.datagrid({
        fitColumns: true,//列自适应
        url: "/charts/salesByGroup.do",
        fit: true,
        columns: [[
            {field: 'groupType', title: '分组类型', width: 100, align: 'center'},
            {field: 'totalAmount', title: '销售总金额', width: 100, align: 'center'},
        ]],
        toolbar: "#tb",//工具
        pagination: true,//分页
        rownumbers: true,//行号
        singleSelect: true//只允许选择一行
    });

    var methodObj = {
        search: function () {
            var companyId = $("[name=companyId]").val();
            var productId = $("[name=productId]").val();

            sales_dataGrid.datagrid('load', {
                companyId:companyId,
                productId:productId
            });
        },
        reload:function () {
            sales_dataGrid.dialog("load");
            var beginTime = $("[name=beginTime]").val();
            var endTime = $("[name=endTime]").val();
            var productId = $("[name=productId]").val();
            var groupType = $("[name=groupType]").val();

            sales_dataGrid.datagrid('load', {
                companyId: companyId,
                productId: productId,
                beginTime: beginTime,
                endTime: endTime,
                groupType: groupType,
            });
        },
        reload: function () {
            sales_dataGrid.dialog("load");
        },
        bar: function () {
            /*点击序列化表单,并且在子窗口中打开拼接的连接地址*/
                var url = "/charts/salesbar.do";
                url = url + "?" + $("#salesForm").serialize();
                art.dialog.open(url,{
                    width: 800,
                    height: 600
                });
        },
        pie: function () {
            /*点击序列化表单,并且在子窗口中打开拼接的连接地址*/
            var url = "/charts/salespie.do";
            url = url + "?" + $("#salesForm").serialize();
            art.dialog.open(url,{
                width: 800,
                height: 600
            });
        }
    };

    //按钮统一绑定事件
    $("a[data-cmd]").click(function () {
        var cmd = $(this).data("cmd");
        methodObj[cmd]();
    });
})
